<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Tomcat处理请求流程 | flyingzc's blog</title><meta name="author" content="flyingzc"><meta name="copyright" content="flyingzc"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="tomcat处理请求组件Server123456789101112131415Server|-- Service|--|-- Connector|--|--|-- Prototal|--|--|--|-- Endpoint|--|--|--|--|-- Acceptor|--|--|--|--|-- Executor|--|--|--|-- Processor|--|--|-- Mapper|--">
<meta property="og:type" content="article">
<meta property="og:title" content="Tomcat处理请求流程">
<meta property="og:url" content="https://flyingzc.github.io/articles/tomcat/tomcat06-request.html">
<meta property="og:site_name" content="flyingzc&#39;s blog">
<meta property="og:description" content="tomcat处理请求组件Server123456789101112131415Server|-- Service|--|-- Connector|--|--|-- Prototal|--|--|--|-- Endpoint|--|--|--|--|-- Acceptor|--|--|--|--|-- Executor|--|--|--|-- Processor|--|--|-- Mapper|--">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://flyingzc.github.io/images/zc-icon.jpeg">
<meta property="article:published_time" content="2019-12-25T16:00:00.000Z">
<meta property="article:modified_time" content="2025-01-21T01:51:41.215Z">
<meta property="article:author" content="flyingzc">
<meta property="article:tag" content="Tomcat">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://flyingzc.github.io/images/zc-icon.jpeg"><script type="application/ld+json">{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "Tomcat处理请求流程",
  "url": "https://flyingzc.github.io/articles/tomcat/tomcat06-request.html",
  "image": "https://flyingzc.github.io/images/zc-icon.jpeg",
  "datePublished": "2019-12-25T16:00:00.000Z",
  "dateModified": "2025-01-21T01:51:41.215Z",
  "author": [
    {
      "@type": "Person",
      "name": "flyingzc",
      "url": "https://flyingzc.github.io/"
    }
  ]
}</script><link rel="shortcut icon" href="/images/zc-icon.jpeg"><link rel="canonical" href="https://flyingzc.github.io/articles/tomcat/tomcat06-request.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="DentpX3LnP_WNgEeFnNIcTZZky-Bby-zL-uI_9GqTAw"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><script>
    (() => {
      
    const saveToLocal = {
      set: (key, value, ttl) => {
        if (!ttl) return
        const expiry = Date.now() + ttl * 86400000
        localStorage.setItem(key, JSON.stringify({ value, expiry }))
      },
      get: key => {
        const itemStr = localStorage.getItem(key)
        if (!itemStr) return undefined
        const { value, expiry } = JSON.parse(itemStr)
        if (Date.now() > expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return value
      }
    }

    window.btf = {
      saveToLocal,
      getScript: (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        Object.entries(attr).forEach(([key, val]) => script.setAttribute(key, val))
        script.onload = script.onreadystatechange = () => {
          if (!script.readyState || /loaded|complete/.test(script.readyState)) resolve()
        }
        script.onerror = reject
        document.head.appendChild(script)
      }),
      getCSS: (url, id) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onload = link.onreadystatechange = () => {
          if (!link.readyState || /loaded|complete/.test(link.readyState)) resolve()
        }
        link.onerror = reject
        document.head.appendChild(link)
      }),
      addGlobalFn: (key, fn, name = false, parent = window) => {
        if (!false && key.startsWith('pjax')) return
        const globalFn = parent.globalFn || {}
        globalFn[key] = globalFn[key] || {}
        globalFn[key][name || Object.keys(globalFn[key]).length] = fn
        parent.globalFn = globalFn
      }
    }
  
      
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode

      const theme = saveToLocal.get('theme')
    
          theme === 'dark' ? activateDarkMode() : theme === 'light' ? activateLightMode() : null
        
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        document.documentElement.classList.toggle('hide-aside', asideStatus === 'hide')
      }
    
      
    const detectApple = () => {
      if (/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)) {
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
  
    })()
  </script><script async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><script>(adsbygoogle = window.adsbygoogle || []).push({
  google_ad_client: '',
  enable_page_level_ads: 'true'
});</script><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":false,"highlightMacStyle":false},
  copy: {
    success: '复制成功',
    error: '复制失败',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'null',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyloadPlugin: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Tomcat处理请求流程',
  isHighlightShrink: false,
  isToc: true,
  pageType: 'post'
}</script><link rel="stylesheet" href="/self/github-dark.css"><meta name="generator" content="Hexo 7.0.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img text-center"><img src="/images/zc-icon.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data text-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">84</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">36</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">29</div></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a class="nav-site-title" href="/"><span class="site-name">flyingzc's blog</span></a><a class="nav-page-title" href="/"><span class="site-name">Tomcat处理请求流程</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">Tomcat处理请求流程</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-12-25T16:00:00.000Z" title="发表于 2019-12-26 00:00:00">2019-12-26</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2025-01-21T01:51:41.215Z" title="更新于 2025-01-21 09:51:41">2025-01-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Tomcat/">Tomcat</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="container post-content" id="article-container"><h1 id="tomcat处理请求"><a href="#tomcat处理请求" class="headerlink" title="tomcat处理请求"></a>tomcat处理请求</h1><h2 id="组件"><a href="#组件" class="headerlink" title="组件"></a>组件</h2><h3 id="Server"><a href="#Server" class="headerlink" title="Server"></a>Server</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">Server<br>|-- Service<br>|--|-- Connector<br>|--|--|-- Prototal<br>|--|--|--|-- Endpoint<br>|--|--|--|--|-- Acceptor<br>|--|--|--|--|-- Executor<br>|--|--|--|-- Processor<br>|--|--|-- Mapper<br>|--|--|-- CoyteAdapter<br>|--|-- Container<br>|--|--|--|-- Host<br>|--|--|--|-- Context<br>|--|--|--|-- Wrapper<br>|--|-- Executor<br></code></pre></td></tr></table></figure>

<h3 id="Http11NioProtocol"><a href="#Http11NioProtocol" class="headerlink" title="Http11NioProtocol"></a>Http11NioProtocol</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">Http11NioProtocol<br>|-- NioEndpoint<br>|--|-- LimitLatch<br>|--|-- Acceptor<br>|--|-- Poller<br>|--|-- Poller池<br>|--|-- SocketProcessor<br>|--|-- Executor<br>|--|-- PollerEvent<br>|--|-- KeyAttachment<br>|--|-- NioBufferHandler<br>|-- Http11ConnectionHandler<br>|-- Http11NioProcessor<br></code></pre></td></tr></table></figure>

<h3 id="Connector"><a href="#Connector" class="headerlink" title="Connector"></a>Connector</h3><p>接收客户端连接并响应</p>
<h3 id="Protocol协议"><a href="#Protocol协议" class="headerlink" title="Protocol协议"></a>Protocol协议</h3><p>协议的抽象.<br>Protocol分类: Http11Protocol,Http11NioProtocol 等.</p>
<h3 id="Http11NioProtocol-1"><a href="#Http11NioProtocol-1" class="headerlink" title="Http11NioProtocol"></a>Http11NioProtocol</h3><p>包含 NioEndpoint 和 Http11NioProcessor</p>
<h3 id="NioEndpoint"><a href="#NioEndpoint" class="headerlink" title="NioEndpoint"></a>NioEndpoint</h3><h3 id="LimitLatch"><a href="#LimitLatch" class="headerlink" title="LimitLatch"></a>LimitLatch</h3><p>连接数控制,nio模式下默认是10000,达到这个阈值后,就会拒绝连接请求.使用AQS实现的一个共享锁.</p>
<h4 id="LimitLatch相关流程"><a href="#LimitLatch相关流程" class="headerlink" title="LimitLatch相关流程"></a>LimitLatch相关流程</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- 初始化最大连接数量<br>    - endpoint.startInternal()<br>        -  initializeConnectionLatch(); 初始化LimitLatch,用于控制连接的数量  <br>            - connectionLimitLatch = new LimitLatch(getMaxConnections()); 根据最大的连接数量来创建  <br><br>- acceptor接收请求前,连接计数+1.若到达最大值则等待其他连接释放<br>    - acceptor.run()<br>        - countUpOrAwaitConnection();// 增加连接计数,若connection数量已经达到了最大等待 socket = serverSocket.accept();  然后再等待连接,若上一步阻塞则不会到此处<br><br>- 连接计数-1<br>    - (!setSocketOptions(socket)) &#123;  //这里主要是将socket加入到poller对象上面去,而且还要设置参数     <br>        countDownConnection();  // 加入poller对象失败了的话,那么将LimitLatch的计数减1 <br>      &#125;<br>    - endpoint.cancelKey()<br>        - countDownConnection();<br></code></pre></td></tr></table></figure>

<h3 id="Acceptor"><a href="#Acceptor" class="headerlink" title="Acceptor"></a>Acceptor</h3><p>接收socket连接<br>通过 serverSocket.accept() 获得 SocketChannel 对象,封装成 org.apache.tomcat.util.net.NioChannel.<br>再将 NioChannel 封装成 PollerEvent, 并将 PollerEvent 压入 events queue里,即<code>ConcurrentLinkedQueue&lt;PollerEvent&gt; events</code>里.</p>
<h3 id="Poller-轮询器"><a href="#Poller-轮询器" class="headerlink" title="Poller 轮询器"></a>Poller 轮询器</h3><p>轮询 events.由 Poller 将就绪的事件 生成 SocketProcessor,交由 Executor 处理.</p>
<h3 id="Poller池"><a href="#Poller池" class="headerlink" title="Poller池"></a>Poller池</h3><p>包含若干 Poller 组件</p>
<h3 id="SocketProcessor"><a href="#SocketProcessor" class="headerlink" title="SocketProcessor"></a>SocketProcessor</h3><p>具体的 http 请求头等解析操作全是 Http11NioProcessor 处理的, 但是是在 NioEndpoint.SocketProcessor 线程的run()方法里调用的.</p>
<ul>
<li>结构(属性)<ul>
<li>NioChannel socket</li>
<li>SocketStatus status</li>
</ul>
</li>
</ul>
<h3 id="Executor"><a href="#Executor" class="headerlink" title="Executor"></a>Executor</h3><p>Executor 拿到 Poller 传过来的 socket 后,将 socket 封装在 SocketProcessor 对象中.<br>然后从 Http11ConnectionHandler 中取出 Http11NioProcessor 对象.</p>
<h3 id="PollerEvent"><a href="#PollerEvent" class="headerlink" title="PollerEvent"></a>PollerEvent</h3><p>对 NioChannel 的包装,用于注册到 Poller.event 队列中.</p>
<ul>
<li>属性<ul>
<li>NioChannel socket<ul>
<li>NioChannel是 非阻塞通道.负责将数据读到缓冲区中,或将数据从缓冲区中写入.</li>
</ul>
</li>
<li>int interestOps; &#x2F;&#x2F; 感兴趣的事件,第一次是OP_REGISTER</li>
<li>KeyAttachment key;&#x2F;&#x2F; KeyAttachment包装nioChannel</li>
</ul>
</li>
</ul>
<h3 id="KeyAttachment"><a href="#KeyAttachment" class="headerlink" title="KeyAttachment"></a>KeyAttachment</h3><ul>
<li>注册到SelectionKey上的附件,对 NioChannel 的包装类.</li>
</ul>
<h3 id="NioBufferHandler"><a href="#NioBufferHandler" class="headerlink" title="NioBufferHandler"></a>NioBufferHandler</h3><ul>
<li>分配nio的buffer的读写空间,内部包含ByteBuffer类型的readbuf和writebuf属性.在构建NioChannel时使用.</li>
</ul>
<h3 id="Http11ConnectionHandler"><a href="#Http11ConnectionHandler" class="headerlink" title="Http11ConnectionHandler"></a>Http11ConnectionHandler</h3><ul>
<li>结构(属性)<ul>
<li><code>protected final Map&lt;S,Processor&lt;S&gt;&gt; connections = new ConcurrentHashMap&lt;S,Processor&lt;S&gt;&gt;();</code><br>  connections 这个 Map维护NioChannel(内部包含socket通道)与processor的关系(如Http11NioProcessor).<br>  所以若processor一次不能读取到 所需的所有数据,就等下一次poller轮询时根据socket找到这个processor继续读取.</li>
</ul>
</li>
</ul>
<h3 id="Http11NioProcessor"><a href="#Http11NioProcessor" class="headerlink" title="Http11NioProcessor"></a>Http11NioProcessor</h3><p>nio方式解析请求头等.</p>
<ul>
<li>结构<ul>
<li>InternalNioInputBuffer</li>
<li>InternalNioOutputBuffer</li>
</ul>
</li>
</ul>
<h3 id="Nio涉及的其他类"><a href="#Nio涉及的其他类" class="headerlink" title="Nio涉及的其他类"></a>Nio涉及的其他类</h3><ul>
<li>NioChannel<ul>
<li>作用<ul>
<li>NioChannel是 非阻塞通道.负责将数据读到缓冲区中,或将数据从缓冲区中写入.</li>
</ul>
</li>
<li>结构<ul>
<li>Nio.SocketChannel</li>
<li>NioEndpoint.NioBufferHandler</li>
</ul>
</li>
</ul>
</li>
<li>SocketProperties<ul>
<li>从server.xml的Connector节点上获取参数值,设置nio的socket属性</li>
</ul>
</li>
</ul>
<h3 id="Mapper"><a href="#Mapper" class="headerlink" title="Mapper"></a>Mapper</h3><ul>
<li>路由</li>
</ul>
<h3 id="CoyoteAdapter"><a href="#CoyoteAdapter" class="headerlink" title="CoyoteAdapter"></a>CoyoteAdapter</h3><ul>
<li>将Connector和Engine适配起来.</li>
</ul>
<h3 id="处理请求"><a href="#处理请求" class="headerlink" title="处理请求"></a>处理请求</h3><h4 id="1-Acceptor线程"><a href="#1-Acceptor线程" class="headerlink" title="1. Acceptor线程"></a>1. Acceptor线程</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- 1.Acceptor线程操作 NioEndpoint中 acceptor.run()<br>- 该acceptor线程一直循环,直到接收到关闭命令<br>- countUpOrAwaitConnection(); 通过 LimitLatch 增加连接计数,若已经到达 最大连接数,则让该acceptor线程等待(直到其他线程释放连接),相当于拒绝掉客户端请求<br>- socket = serverSock.accept(); 接收新连接,返回SocketChannel客户端连接对象,这里用的是阻塞模式. 整个循环靠此处阻塞,直到接收到客户端请求才继续往下走<br>- setSocketOptions(socket) 设置socket属性,这里面主要 将socketChannel包装到nioChannel里. 再将nioChannel包装到PollerEvent里,并放入轮询的事件队列events中<br>    - socket.configureBlocking(false); 将socket连接通道设置为非阻塞模式<br>    - Socket sock = socket.socket(); 从nio.SocketChannel中获取java.net.Socket<br>    - socketProperties.setProperties(sock); 设置socket的参数值(从server.xml的Connector节点上获取参数值), 如 socket发送,接收的大小.心跳检测,超时时长等<br>    - NioChannel channel = nioChannels.poll(); 构造NioChannel对象,从ConcurrentLinkedQueue (即NioChannel的缓存队列) 中取<br>        - 附:ConcurrentLinkedQueue&lt;NioChannel&gt;类型的nioChannels对象的作用 将关闭通道的nioChannel放入Queue缓存起来,方便复用.复用时替换掉其内部的SocketChannel对象即可, NioChannel包含的其他属性只需做重置操作即可.当获取不到时再重新创建<br>        - 取不到则新创建 channel = new NioChannel(socket, bufhandler); 将socketChannel对象 封装到NioChannel对象中.非SSL的.  <br>        1.socket参数: 进行读写操作的nio.SocketChannel对象.  <br>        2.bufhandler参数: 为NioChannel.NioBufferHandler.这个类用于 根据xml配置 分配nio的buffer的读写空间. 是对nio.Buffer的封装. 提供用于操作 待写入SocketChannel缓存区 和  读取SocketChannel的缓冲区的方法.<br>    - getPoller0().register(channel); 将新接收到的SocketChannel注册到event队列上 (将nioChannel包装成PollerEvent 注册到轮询线程events上)<br>        - getPoller0() 轮询当前的Poller线程数组,从中取出一个Poller并返回<br>        - Poller.register() 将新接收到的SocketChannel注册到event队列上(nioChannel包装成PollerEvent 注册到轮询线程) <br>            1.创建KeyAttachment并与poller关联;  2.将channelSocket(nioChannel)包装成PollerEvent 注册到事件队列(events)中;  3.是否需要对selector wakeup的处理<br>            - new KeyAttachment(socket) 创建或从缓存中取出KeyAttachment并重置. KeyAttachment是对NioChannel的一层包装<br>            - ka.reset(this,socket,getSocketProperties().getSoTimeout()); 重置KeyAttachment对象中Poller,NioChannel等成员变量的引用<br>            - ka.interestOps(SelectionKey.OP_READ); 设置keyAttachement 读操作(SelectionKey.OP_READ) 为感兴趣的操作<br>            - PollerEvent r = eventCache.poll(); 从通道缓存队列中取出一个PollerEvent. 取到则重置属性,取不到则新建<br>                - 取不到则新建 r = new PollerEvent(socket,ka,OP_REGISTER); 若取出为空,则新建.将nioChannel包装到PollerEvent对象中. 否则,重置PollerEvent中的属性. 并注册一个OP_REGISTER(对应)928行pollerEvent.run()里<br>            - poller.addEvent(r); 将PollerEvent添加到轮询队列(poller.events)中. 相当于每个poller都维护了一个event队列,代表这个poller需要处理的事件列表<br>                - events.offer(event); 将event添加到events队列中<br>                - if ( wakeupCounter.incrementAndGet() == 0 ) selector.wakeup(); <br>                    使一个还未返回的 select() 方法立即返回.即若当前事件队列中 没有事件,则唤醒处于阻塞在selector.select()状态上的线程(会唤醒selector).与1208行对应<br>                    - 附:Poller类中protected AtomicLong wakeupCounter = new AtomicLong(0l);的作用 唤醒 多路复用器(即nio中的selector)的条件阈值.<br>                    作用: 1.告诉Poller当前有多少个新连接,这样当Poller进行selector的操作时,可以选择是否需要阻塞来等待读写请求到达; <br>                    2.标识Poller在进行select选择时,是否有连接到达.如果有,就让当前的阻塞调用立即返回<br></code></pre></td></tr></table></figure>

<h4 id="2-Poller线程"><a href="#2-Poller线程" class="headerlink" title="2. Poller线程"></a>2. Poller线程</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- 2.Poller线程操作 poller.run()<br>- poller.events() 从events队列中取出pollerEvent对象并run(); 即处理轮询器的事件队列中的事件,若事件队列是空的则返回false,否则返回true. 每个poller都有一个events队列,poller会一直循环取出里面的event进行处理<br>    - while ( (r = events.poll()) != null ) 循环从events队列 中 逐个取出PollerEvent事件,运行每一个PollerEvent的处理逻辑<br>    - r.run(); 运行每一个PollerEvent的处理逻辑.即PollerEvent.run(). 注意,此处还是在当前线程中完成.因为调用的是r.run()不是r.start(), 可以理解成只是一个普通方法,在当前而不是新起一个线程<br>        - PollerEvent.run() 若这个pollerEvent中的interestOps是OP_REGISTER, 则将pollerEvent.nioChannel.socketChannel注册到poller.selector上<br>            - if ( interestOps == OP_REGISTER ) <br>            // PollerEvent最初的interestOps就是OP_REGISTER socket.getIOChannel().register(socket.getPoller().getSelector(), SelectionKey.OP_READ, key); <br>            从nioChannel中获取socketChannel,从poller中获取selector. 则此时将socketChannel.register(selector, OP_READ, keyAttachment),即将socketChannel向selector注册读感兴趣事件.  <br>    - 上一步r.run()执行完后 ((PollerEvent)r).reset(); eventCache.offer((PollerEvent)r); 只要从events中取出后,便重置PollerEvent并缓存到eventCache中, 方便复用PollerEvent对象<br>- Iterator&lt;SelectionKey&gt; iterator = keyCount &gt; 0 ? selector.selectedKeys().iterator() : null; 根据向selector中注册的key遍历channel中已经就绪的SelectionKey,并处理这些key<br>    - iterator遍历 SelectionKey sk = iterator.next(); KeyAttachment attachment = (KeyAttachment)sk.attachment(); 这里的attachment()返回的就是在register()中注册的KeyAttachement,该对象是对socket的包装类  attachment.access();更新 通道最近一次发生事件的事件,防止因超时没有事件发生而被剔除出selector iterator.remove();从迭代器中移除掉(因为下一步processKey就处理它)<br>    - processKey(sk, attachment); 具体处理通道的逻辑,交由SocketProcessor处理 sk为SelectionKey<br>        - NioChannel channel = attachment.getChannel(); 从keyAttachment中获取nioChannel<br>        - if (sk.isReadable() || sk.isWritable() ) &#123; SelectionKey处理通道(channel)发生的 读写事件 &#125;<br>            - unreg(sk, attachment, sk.readyOps()); 在通道上 注销 对已经发生事件的关注, 防止通道对同一个事件不断select的问题<br>            - 若sk.isReadable() 通道读事件的处理<br>                - processSocket(channel, SocketStatus.OPEN_READ, true) 把SocketProcessor交给Excutor去执行.<br>                    - 创建SocketProcessor实例 SocketProcessor sc = processorCache.poll(); 从SocketProcessor缓存队列中取出一个来处理socket, 没有则新建.<br>                    有则重置属性 new SocketProcessor(socket,status) socketProcessor内的socket属性为NioChannel类型<br>                    - getExecutor().execute(sc); 将socketProccessor任务交由org.apache.tomcat.util.threads.ThreadPoolExecutor线程池处理, 则该线程池会调用socketProcessor.run() .<br>                    即SocketProcessor实例是对NioChannel的封装.由Executor执行socketProcessor.run()方法<br></code></pre></td></tr></table></figure>

<h4 id="3-SocketProcessor线程"><a href="#3-SocketProcessor线程" class="headerlink" title="3. SocketProcessor线程"></a>3. SocketProcessor线程</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- 3.SocketProcessor线程操作 socketProcessor.run()<br>- socketProcessor.run()总体逻辑 1.使用nio方式 读取套接字 并进行处理, 输出响应报文;2.连接计数器减1,腾出通道;3.关闭套接字<br>- SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); 从socket(SocketProcessor的成员变量NioChannel类型)中获取SelectionKey<br>- ka = (KeyAttachment)key.attachment(); 从SelectionKey中获取关联的keyAttachment<br>- synchronized (socket) &#123;// 对NioChannel加锁     doRun(selectionkey, keyAttachment); &#125;  socketProcessor的具体逻辑<br>    - state = handler.process(ka, status); 此处handler为Http11NioProtocol$Http11ConnectionHandler, 这个静态类虽然在Http11NioProtocol内部,但是它持有Http11NioProtocol对象<br>        - 调用父类AbstractProtocol.AbstractConnectionHandler.process() 该内部类的主要逻辑是获取HttpProcessor,缓存取 或新建<br>            - state = processor.process(wrapper); 使用Http11NioProcessor处理socket请求. 此处processor为Http11NioProcessor对象<br>                - 父类AbstractHttp11Processor.process() 其实后面操作全是Http11NioProcessor处理了, 但是是在Endpoint.SocketProcessor线程的run()方法里调用的<br>                    - getInputBuffer().init(socketWrapper, endpoint); 初始化 输入流.将socket的输入流 赋值给InterInputBuffer的inputStream属性<br>                        - InternalNioInputBuffer.init() 设置internalNioInputBuffer的成员变量.如socket,buf大小,SelectorPool<br>                    - getOutputBuffer().init(socketWrapper, endpoint); 初始化 输出流<br>                        - 设置selectorPool和socket<br>                    - getInputBuffer().parseRequestLine(keptAlive))  解析请求行<br>                        - 即InternalNioInputBuffer.parseRequestLine()<br>                            - InternalNioInputBuffer.fill(true,false) 读取socket数据到buf字节数组中. timeout:是否有超时;  block:是否阻塞读<br>                                - InternalNioInputBuffer.readSocket() <br>                                    从socket中读取数据到buf字节数组中. 从底层socket读取数据.有阻塞式 和 非阻塞式 从 socket中读. <br>                                    若采用nio,在处理http请求的requestLine和header时非阻塞.  <br>                                    处理body时必须阻塞 (因为读取body部分的 代码一般是在servlet部分控制的即上层代码控制,已经超出tomcat控制范围). <br>                                    - socket.getBufHandler().getReadBuffer().clear();  清空nio.ByteBuffer,方便下面将socket里读取的新数据写进去<br>                                    - 由于block=false,此处非阻塞读 即nRead = socket.read(socket.getBufHandler().getReadBuffer());<br>                                        - sc.read(dst); 其实就是socketChannel.read(buffer) // read into buffer<br>                                    - if (nRead &gt; 0) &#123;// 若有数据读取出来     <br>                                        socket.getBufHandler().getReadBuffer().flip();// 调用ByteBuffer.flip()将buffer切换到读模式     <br>                                        socket.getBufHandler().getReadBuffer().limit(nRead);// 设置buffer.limit就是本次读取的长度     <br>                                        expand(nRead + pos);// 检查当前对象的buf字节数组容量是否够大,若不够则扩容     <br>                                        socket.getBufHandler().getReadBuffer().get(buf, pos, nRead);// 将socket读取的数据 转移到当前对象的buf数组中     <br>                                        lastValid = pos + nRead;// 更新最后一个有效数据的下标     <br>                                        return nRead; &#125;<br>                    - getInputBuffer().parseHeaders() 解析请求头<br>                    - adapter.service(request, response); 将socket封装成request,response,再交给adapter做后续处理<br>                        - coyteAdapter.postParseRequest()<br>                            - 匹配请求对应的Host,Context,Wrapper <br>                            connector.getMapper().map(serverName, decodedURI, version, request.getMappingData()); <br>                            request.setContext((Context) request.getMappingData().context); <br>                            request.setWrapper((Wrapper) request.getMappingData().wrapper);<br>                        - connector.getService().getContainer().getPipeline().getFirst().invoke(request, response); 调用container.调用StandardEngine的pipeline 处理request和response<br>                            - StandardEngineValve.invoke()中 host.getPipeline().getFirst().invoke(request, response);<br>                                - AccessLogValve.invoke()中 getNext().invoke(request, response); 没做事,直接调下一个管道<br>                                    - ErrorReportValve.invoke() tomcat错误输出页面<br>                                        - StandardHostValve.invoke() context.getPipeline().getFirst().invoke(request, response);<br>                                            - AuthenticatorBase.invoke() getNext().invoke(request, response);<br>                                                - StandardContextValve.invoke() wrapper.getPipeline().getFirst().invoke(request, response); 调用wrapper的pipeline来处理请求,即StandardWrapperValve<br>                                                    - StandardWrapperValve.invoke() filterChain.doFilter(request.getRequest(), response.getResponse()); 调用fiterChain来处理 request 和 response<br>                                                        - ApplicationFilterChain.doFilter()中 internalDoFilter(request,response);<br>                                                            - filter.doFilter(request, response, this); 调用具体filter.doFilter方法<br>                                                                - WsFilter.doFilter()<br>                                                                    - ApplicationFilterChain.internalDoFilter()中 servlet.service(request, response); 调用对应servlet.service()<br></code></pre></td></tr></table></figure>
<link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/markmap-toolbar@0.18.10/dist/style.css"><script src="https://fastly.jsdelivr.net/npm/d3@7"></script><script src="https://fastly.jsdelivr.net/npm/markmap-view@0.18.10"></script><script src="https://fastly.jsdelivr.net/npm/markmap-toolbar@0.18.10"></script>
<link rel="stylesheet" href="/css/markmap.css">

<script src="/js/markmap.js"></script>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://flyingzc.github.io">flyingzc</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://flyingzc.github.io/articles/tomcat/tomcat06-request.html">https://flyingzc.github.io/articles/tomcat/tomcat06-request.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来源 <a href="https://flyingzc.github.io" target="_blank">flyingzc's blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Tomcat/">Tomcat</a></div><div class="post-share"><div class="social-share" data-image="/images/zc-icon.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a class="pagination-related" href="/articles/tomcat/tomcat01-lifecycle.html" title="Tomcat Lifecycle"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-12-19</div><div class="info-item-2">Tomcat Lifecycle</div></div><div class="info-2"><div class="info-item-1">LifeCycleLifeCycle 相关类LifeCycle 接口中的状态扭转注释,如下: 12345678910111213141516171819202122232425262728*            start()*  -----------------------------*  |                           |*  | init()                    |* NEW -»-- INITIALIZING        |* | |           |              |     ------------------«-----------------------* | |           |auto          |     |                                        |* | |          \|/    start() \|/   \|/     auto          auto         stop() |* | |     ...</div></div></div></a><a class="pagination-related" href="/articles/tomcat/tomcat01_debug.html" title="Tomcat Debug"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-29</div><div class="info-item-2">Tomcat Debug</div></div><div class="info-2"><div class="info-item-1">tomcat debug方式1. tomcat远程debug,这种方式正常用于sit或者灰度环境调试问题使用,当然localhost也能这样debug.在 startup.sh 中配置 1SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=19999  方式2. 在idea中启动tomcat debug,需要添加tomcat的jar依赖.这种方式用于本地看tomcat源码或者定位本地起的项目中tomcat部分的问题时可以使用. 12345678910111213&lt;dependency&gt;    &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;    &lt;artifactId&gt;tomcat-catalina&lt;/artifactId&gt;    &lt;version&gt;7.0.82&lt;/version&gt;...</div></div></div></a><a class="pagination-related" href="/articles/tomcat/tomcat03-session.html" title="Tomcat Session机制"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-12-20</div><div class="info-item-2">Tomcat Session机制</div></div><div class="info-2"><div class="info-item-1">tomcat session相关类12345org.apache.catalina.ManagerStandardManagerSessionIdGenerator  Manager实现类Manager 用于管理 session.默认实现是 StandardManager,基类 ManagerBase. 123456789101112Manager    ClusterManager (org.apache.catalina.ha)        ClusterManagerBase (org.apache.catalina.ha.session)            BackupManager (org.apache.catalina.ha.session)            DeltaManager (org.apache.catalina.ha.session)    ManagerBase (org.apache.catalina.session)        PersistentManagerBase (org.apache.catalina.session)...</div></div></div></a><a class="pagination-related" href="/articles/tomcat/tomcat02-start.html" title="Tomcat启动流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-12-19</div><div class="info-item-2">Tomcat启动流程</div></div><div class="info-2"><div class="info-item-1">tomcat...</div></div></div></a><a class="pagination-related" href="/articles/tomcat/tomcat04-distribute-session.html" title="Tomcat实现分布式session"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-12-20</div><div class="info-item-2">Tomcat实现分布式session</div></div><div class="info-2"><div class="info-item-1">tomcat实现分布式sessiontomcat-redis-session-manager 使用Copy the following files into the TOMCAT_BASE&#x2F;lib directory: 123tomcat-redis-session-manager-VERSION.jarjedis-2.5.2.jarcommons-pool2-2.2.jar  配置 TOMCAT_HOME&#x2F;conf&#x2F;context.xml 12345&lt;Valve className=&quot;com.radiadesign.catalina.session.RedisSessionHandlerValve&quot; /&gt;&lt;Manager className=&quot;com.radiadesign.catalina.session.RedisSessionManager&quot;         host=&quot;localhost&quot;            port=&quot;6379&quot;...</div></div></div></a></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info text-center"><div class="avatar-img"><img src="/images/zc-icon.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info-name">flyingzc</div><div class="author-info-description">不积跬步无以至千里<br/>不积小流无以成江海</div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">84</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">36</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">29</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/FlyingZC"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons"><a class="social-icon" href="https://github.com/FlyingZC" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">FlyingZC's Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#tomcat%E5%A4%84%E7%90%86%E8%AF%B7%E6%B1%82"><span class="toc-number">1.</span> <span class="toc-text">tomcat处理请求</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6"><span class="toc-number">1.1.</span> <span class="toc-text">组件</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Server"><span class="toc-number">1.1.1.</span> <span class="toc-text">Server</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Http11NioProtocol"><span class="toc-number">1.1.2.</span> <span class="toc-text">Http11NioProtocol</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Connector"><span class="toc-number">1.1.3.</span> <span class="toc-text">Connector</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Protocol%E5%8D%8F%E8%AE%AE"><span class="toc-number">1.1.4.</span> <span class="toc-text">Protocol协议</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Http11NioProtocol-1"><span class="toc-number">1.1.5.</span> <span class="toc-text">Http11NioProtocol</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#NioEndpoint"><span class="toc-number">1.1.6.</span> <span class="toc-text">NioEndpoint</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#LimitLatch"><span class="toc-number">1.1.7.</span> <span class="toc-text">LimitLatch</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#LimitLatch%E7%9B%B8%E5%85%B3%E6%B5%81%E7%A8%8B"><span class="toc-number">1.1.7.1.</span> <span class="toc-text">LimitLatch相关流程</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Acceptor"><span class="toc-number">1.1.8.</span> <span class="toc-text">Acceptor</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Poller-%E8%BD%AE%E8%AF%A2%E5%99%A8"><span class="toc-number">1.1.9.</span> <span class="toc-text">Poller 轮询器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Poller%E6%B1%A0"><span class="toc-number">1.1.10.</span> <span class="toc-text">Poller池</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SocketProcessor"><span class="toc-number">1.1.11.</span> <span class="toc-text">SocketProcessor</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Executor"><span class="toc-number">1.1.12.</span> <span class="toc-text">Executor</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#PollerEvent"><span class="toc-number">1.1.13.</span> <span class="toc-text">PollerEvent</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#KeyAttachment"><span class="toc-number">1.1.14.</span> <span class="toc-text">KeyAttachment</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#NioBufferHandler"><span class="toc-number">1.1.15.</span> <span class="toc-text">NioBufferHandler</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Http11ConnectionHandler"><span class="toc-number">1.1.16.</span> <span class="toc-text">Http11ConnectionHandler</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Http11NioProcessor"><span class="toc-number">1.1.17.</span> <span class="toc-text">Http11NioProcessor</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Nio%E6%B6%89%E5%8F%8A%E7%9A%84%E5%85%B6%E4%BB%96%E7%B1%BB"><span class="toc-number">1.1.18.</span> <span class="toc-text">Nio涉及的其他类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Mapper"><span class="toc-number">1.1.19.</span> <span class="toc-text">Mapper</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#CoyoteAdapter"><span class="toc-number">1.1.20.</span> <span class="toc-text">CoyoteAdapter</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%84%E7%90%86%E8%AF%B7%E6%B1%82"><span class="toc-number">1.1.21.</span> <span class="toc-text">处理请求</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-Acceptor%E7%BA%BF%E7%A8%8B"><span class="toc-number">1.1.21.1.</span> <span class="toc-text">1. Acceptor线程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-Poller%E7%BA%BF%E7%A8%8B"><span class="toc-number">1.1.21.2.</span> <span class="toc-text">2. Poller线程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-SocketProcessor%E7%BA%BF%E7%A8%8B"><span class="toc-number">1.1.21.3.</span> <span class="toc-text">3. SocketProcessor线程</span></a></li></ol></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite03-transaction-begin.html" title="Apache Ignite 开启事务执行流程">Apache Ignite 开启事务执行流程</a><time datetime="2025-10-10T16:00:00.000Z" title="发表于 2025-10-11 00:00:00">2025-10-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite02-transaction.html" title="Apache Ignite 分布式事务原理">Apache Ignite 分布式事务原理</a><time datetime="2025-09-17T16:00:00.000Z" title="发表于 2025-09-18 00:00:00">2025-09-18</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite01-build.html" title="Apache Ignite IDEA 环境搭建">Apache Ignite IDEA 环境搭建</a><time datetime="2025-09-10T16:00:00.000Z" title="发表于 2025-09-11 00:00:00">2025-09-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/druid/druid01-resultset-leak.html" title="ShardingSphere JDBC 使用 Druid 连接池 ResultSet 内存泄露分析">ShardingSphere JDBC 使用 Druid 连接池 ResultSet 内存泄露分析</a><time datetime="2025-06-30T16:00:00.000Z" title="发表于 2025-07-01 00:00:00">2025-07-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/jmeter/jmeter01-shardingsphere.html" title="Jmeter 压测 ShardingSphere">Jmeter 压测 ShardingSphere</a><time datetime="2025-06-30T16:00:00.000Z" title="发表于 2025-07-01 00:00:00">2025-07-01</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2025 By flyingzc</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>